package com.glodon.paas.databag.dao;

import java.util.List;

import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;
import org.springframework.stereotype.Repository;

import com.glodon.paas.databag.model.Databag;

@Repository
public interface DatabagRepository extends CrudRepository<Databag, String> {

    public List<Databag> findBySourceAndLocalIdAndVersion(String source, String localId, String version);

    @Modifying
    @Query("update Databag t set t.token = null where t.token=?1")
    public int clearPublicByToken(String token);

    @Modifying
    @Query("update Databag t set t.token = null where t.id=?1")
    public int clearPublicById(String databagId);

    public Databag findByToken(String token);

    @Modifying
    @Query("update Databag t set t.token = ?2 where t.id=?1")
    public int setPublicById(String databagId, String token);

}
